#1. 确定CMake的最低版本需求
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)

#2. 确定工程名
PROJECT(ParserCTP LANGUAGES CXX)
SET(CMAKE_CXX_STANDARD 17)

SET(SRC  
	${PROJECT_SOURCE_DIR}/ParserCTP.cpp
	${PROJECT_SOURCE_DIR}/ParserCTP.h
)

SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build_${PLATFORM}/${CMAKE_BUILD_TYPE}/bin)

INCLUDE_DIRECTORIES(${INCS})
LINK_DIRECTORIES(${LNKS})
ADD_LIBRARY(ParserCTP SHARED ${SRC})

IF (MSVC)
ELSE (GNUCC)
	SET(LIBS
		boost_thread
		boost_filesystem
		dl
	)
	TARGET_LINK_LIBRARIES(ParserCTP ${LIBS})
ENDIF()

IF (MSVC)
ELSE (GNUCC)
	SET_TARGET_PROPERTIES(ParserCTP PROPERTIES
		CXX_VISIBILITY_PRESET hidden
		C_VISIBILITY_PRESET hidden
		VISIBILITY_INLINES_HIDDEN 1
        LINK_FLAGS_RELEASE -s)
ENDIF ()

set(CTPDIR ${CMAKE_SOURCE_DIR}/../API/CTP6.3.15)
set(WTPY_Linux_DIR ${CMAKE_SOURCE_DIR}/../wtpy/wrapper/linux)
set(DIST_WtCtaRunner_DIR ${CMAKE_SOURCE_DIR}/../dist/WtCtaRunner)
set(DIST_QuoteFactory_DIR ${CMAKE_SOURCE_DIR}/../dist/QuoteFactory)

add_custom_command(TARGET ParserCTP POST_BUILD
	COMMAND ${CMAKE_COMMAND} -E
	copy ${CTPDIR}/linux/thostmduserapi_se.so ${WTPY_Linux_DIR}/parsers/

    COMMAND ${CMAKE_COMMAND} -E
	copy ${LIBRARY_OUTPUT_PATH}/libParserCTP.so ${WTPY_Linux_DIR}/parsers/

	COMMAND ${CMAKE_COMMAND} -E
	copy ${CTPDIR}/linux/thostmduserapi_se.so ${DIST_WtCtaRunner_DIR}/parsers/

    COMMAND ${CMAKE_COMMAND} -E
	copy ${LIBRARY_OUTPUT_PATH}/libParserCTP.so ${DIST_WtCtaRunner_DIR}/parsers/

	COMMAND ${CMAKE_COMMAND} -E
	copy ${CTPDIR}/linux/thostmduserapi_se.so ${DIST_QuoteFactory_DIR}/parsers/

    COMMAND ${CMAKE_COMMAND} -E
	copy ${LIBRARY_OUTPUT_PATH}/libParserCTP.so ${DIST_QuoteFactory_DIR}/parsers/)